﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Reflection;
using XT.Exam.Common;

namespace XT.Exam.Factory
{
    public abstract class AbstractFactory<T>
    {
        //获取配置的DAL命名空间
        static readonly string _assemblyName = ConfigHelper.GetAppSettings("DataAccessAssemblyName");

        /// <summary>
        /// 抽象创建DAL实例
        /// </summary>
        /// <param name="DataAccessfullName">需要实例化的类名</param>
        /// <returns></returns>
        public static T CreateDataAccess(string DataAccessfullName)
        {
            T obj = (T)Assembly.Load(_assemblyName).CreateInstance(_assemblyName + "." + DataAccessfullName);
            if (obj == null)
            {
                throw new Exception("使用反射从程序集 " + _assemblyName + " 里创建对象 " + DataAccessfullName + " 时出错");
            }
            
            return obj;
        }
    }
}
